/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.supinfo.youfood.dao.jpa;

import com.supinfo.youfood.dao.TypeEmployeDao;
import com.supinfo.youfood.entity.TypeEmploye;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author TaKeO
 */
@Stateless
public class JpaTypeEmployeDao implements TypeEmployeDao{

    @PersistenceContext
    EntityManager em;
    
    @Override
    public TypeEmploye findTypeEmployeById(Long id) 
    {
        return em.find(TypeEmploye.class, id);
    }

    @Override
    public List<TypeEmploye> getAllTypeEmploye() {
        String query = "SELECT te "+
                        "FROM TypeEmploye te";
        Query result = em.createQuery(query);
        return (List<TypeEmploye>)result.getResultList();
    }

    @Override
    public void refreshTypeEmploye(TypeEmploye typeEmploye) {
        em.merge(typeEmploye);
    }

    @Override
    public List<TypeEmploye> getGerantTypeEmploye() {
        String query = "SELECT te "+
                        "FROM TypeEmploye te "+
                        "WHERE te.droits <= 600";
        Query result = em.createQuery(query);
        return (List<TypeEmploye>)result.getResultList();
    }
    
}
